﻿using BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

using Common;


namespace PropertyAppraisal
{
    public partial class LiXiangList : System.Web.UI.Page
    {
        //部门表
        private static DepartmentBll Depbll = new DepartmentBll();
        //借款人表
        private static Loan_InfoBll Loanbll = new Loan_InfoBll();
        //项目信息表
        private static Basic_InfoBll Basicbll = new Basic_InfoBll();
        protected void Page_Load(object sender, EventArgs e)
        {
        }



        /// <summary>
        /// 显示登记列表
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public static string showDeng()
        {
            var result = Basicbll.DList();
            return JsonConvert.SerializeObject(result);
        }

        /// <summary>
        ///导出
        /// </summary>
        /// <returns></returns>
         [WebMethod]
        public static string daochu(string id)
        {
            var result = Basicbll.Back(id).FirstOrDefault();
            //模板地址
            string TemplateName = System.Web.HttpContext.Current.Server.MapPath("\\files\\五组地产评估模板.doc");

             var dates=DateTime.Now.ToString("yyyyMMddHHmmss");
            //保存地址
            string SaveName = System.Web.HttpContext.Current.Server.MapPath(string.Format("\\files\\五组地产评估模板{0}.doc",dates));
            //模板内容
            List<WordsTemp> lwt = new List<WordsTemp>();
            lwt.Add(new WordsTemp() { Name = "借款人", Value = result.Loan_Name });
            lwt.Add(new WordsTemp() { Name = "借款人身份证号", Value = result.Loan_IdCard });
            lwt.Add(new WordsTemp() { Name = "部门", Value = result.Department_Name });


            lwt.Add(new WordsTemp() { Name = "编号", Value = result.ProjectNumber });
            lwt.Add(new WordsTemp() { Name = "出具年", Value = result.Issue_Time.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "出具月", Value = result.Issue_Time.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "出具日", Value = result.Issue_Time.Day.ToString() });
            lwt.Add(new WordsTemp() { Name = "登记年", Value = result.Basic_CreateTime.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "登记月", Value = result.Basic_CreateTime.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "登记日", Value = result.Basic_CreateTime.Day.ToString() });
            lwt.Add(new WordsTemp() { Name = "建筑面积", Value = result.Basic_Acreage.ToString() });
            lwt.Add(new WordsTemp() { Name = "剩余年", Value = result.Surplus_Years.ToString() });
            lwt.Add(new WordsTemp() { Name = "最高贷款额", Value = result.Basic_Quota.ToString() });


            lwt.Add(new WordsTemp() { Name = "地址", Value = result.Floor_Address.ToString() });
            lwt.Add(new WordsTemp() { Name = "用途", Value = result.Dictionary_Name.ToString() });
            lwt.Add(new WordsTemp() { Name = "当天年", Value = DateTime.Now.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "当天月", Value = DateTime.Now.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "当天日", Value = DateTime.Now.Day.ToString() });

            CommonWords.Word(TemplateName, SaveName, lwt);
            var zhi = string.Format(urlconvertor(SaveName));
            return  zhi;
        }

         /// <summary>
         /// 本地路径转换成URL相对路径
         /// </summary>
         /// <param name="imagesurl1"></param>
         /// <returns></returns>
         private static string urlconvertor(string imagesurl1)
         {
             string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
             string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //转换成相对路径
             imagesurl2 = imagesurl2.Replace(@"\", @"/");
             //imagesurl2 = imagesurl2.Replace(@"Aspx_Uc/", @"");
             return "/" + imagesurl2;
         }

    }
}